#ifndef CONTEXT_INL
#define CONTEXT_INL

#include <any>
#include <cstdio>

namespace task
{
template<class T>
void Context::setData(const std::string &name, const T &value)
{
    std::any data = value;
    setData(name, data);
}
template<class T>
T Context::data(const std::string &name, const T &default_data) const
{
    bool is_find = true;
    std::any value = getData(name, &is_find);
    if (!is_find)
    {
        return default_data;
    }
    try
    {
        return std::any_cast<T>(value);
    }
    catch (std::exception &e)
    {
        EASE_ERROR("context any_cast exception, %s", e.what());
        return default_data;
    }
}
template<class T>
bool Context::getData(const std::string &name, T &data) const
{
    bool is_find = true;
    std::any value = getData(name, &is_find);
    if (!is_find)
    {
        return false;
    }
    try
    {
        data = std::move(std::any_cast<T>(value));
        return true;
    }
    catch (std::exception &e)
    {
        EASE_ERROR("context any_cast exception, %s", e.what());
        return false;
    }
}
}

#endif //CONTEXT_INL
